package com.base.vistter.iframe.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.base.vistter.iframe.entity.SysTeamUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface SysTeamUserMapper extends BaseMapper<SysTeamUser> {

    @Select({"<script>" ,
                "SELECT COUNT(0) FROM sys_team_user stu ",
                "LEFT JOIN sys_user su ON stu.user_id = su.id ",
                "WHERE stu.team_id = #{teamId} AND stu.is_delete = 0 AND su.is_delete = 0 AND su.`status` = 0 ",
                "<if test='username != null'>",
                    "AND su.username like '%${username}%' ",
                "</if>",
                "<if test='phone != null'>",
                    "AND su.phone like '%${phone}%' ",
                "</if>",
            "</script>"})
    long selectUserCount(@Param("teamId") Integer teamId, @Param("username") String username, @Param("phone") String phone);

    @Select({"<script>" ,
            "SELECT stu.id, su.id as userId, su.username, su.realname, su.work_no, su.phone,stu.create_date FROM sys_team_user stu ",
            "LEFT JOIN sys_user su ON stu.user_id = su.id ",
            "WHERE stu.team_id = #{teamId} AND stu.is_delete = 0 AND su.is_delete = 0 AND su.`status` = 0 ",
            "<if test='username != null'>",
            "AND su.username like '%${username}%' ",
            "</if>",
            "<if test='phone != null'>",
            "AND su.phone like '%${phone}%' ",
            "</if>",
            "limit #{start},#{size}",
            "</script>"})
    List<Map<String,Object>> selectUserList(@Param("teamId") Integer teamId, @Param("username") String username, @Param("phone") String phone, long start ,long size);

}

